﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMS.Model;
using System.Data.SqlClient;
using System.Data;
using System.Data.Common;

namespace MMS.DAL
{
    public class GoodsService:IGoodsService
    {
        
        #region IGoodsService 成员

        public List<GoodsInfo> QueryListBycode(string code)
        {
            List<GoodsInfo> list = new List<GoodsInfo>();
            DBHelper DB = new SqlServerDBHelper();
            DbDataReader db = DB.ExecuteReader("select * from GoodsInfo where GoodsCode like '%" + code + "%'");
             while (db.Read())
             {
                 GoodsInfo GI = new GoodsInfo();
                 if (db["GoodsCode"] != DBNull.Value)
                 {
                    GI.GoodsCode = db["GoodsCode"].ToString();
                 }
                 if (db["GoodsName"] != DBNull.Value)
                 {
                     GI.GoodsName = db["GoodsName"].ToString();
                 }
                 if (db["OriginPrice"] != DBNull.Value)
                 {
                    GI.OriginPrice = Convert.ToInt32(db["OriginPrice"]);
                 }
                 if (db["SalePrice"] != DBNull.Value)
                 {
                    GI.SalePrice = Convert.ToInt32(db["SalePrice"]);
                 }
                 if (db["Stock"] != DBNull.Value)
                 {
                    GI.Stock = db["Stock"].ToString();
                 }
                 if (db["Unit"] != DBNull.Value)
                 {
                    GI.Unit = db["Unit"].ToString();
                 }
                 if (db["Supplier"] != DBNull.Value)
                 {
                    GI.Supplier = Convert.ToInt32(db["Supplier"]);
                 }
                 if (db["Company"] != DBNull.Value)
                 {
                    GI.Company = Convert.ToInt32(db["Company"]);
                 }
                 if (db["GoodsState"] != DBNull.Value)
                 {
                    GI.GoodsState = Convert.ToInt32(db["GoodsState"]);
                 }
                 list.Add(GI);
             }
            
            ///申明集合
            //string DB_CONNECTION_STRING = @"Data Source=.\SQLEXPRESS;Initial Catalog=mmsdb;Integrated Security=True";
            //SqlDataAdapter da = new SqlDataAdapter("select * from GoodsInfo where GoodsCode = '"+GoodsCode+"'",DB_CONNECTION_STRING);
            return list;
        }

        public GoodsInfo QueryGoodsInfo(string code)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
